package com.easylinkin.linkappapi.photoalbum.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.inspection.dto.ElectricCheckPhotoAlbumDTO;
import com.easylinkin.linkappapi.inspection.dto.ElectricCheckPhotoAlbumQueryDTO;
import com.easylinkin.linkappapi.inspection.service.ElectricCheckService;
import com.easylinkin.linkappapi.quality.dto.QualityAppraisingExcellentPhotoAlbumDTO;
import com.easylinkin.linkappapi.quality.dto.QualityAppraisingExcellentPhotoAlbumQueryDTO;
import com.easylinkin.linkappapi.quality.dto.QualityQuestionPhotoAlbumDTO;
import com.easylinkin.linkappapi.quality.dto.QualityQuestionPhotoAlbumQueryDTO;
import com.easylinkin.linkappapi.quality.service.QualityAppraisingExcellentService;
import com.easylinkin.linkappapi.quality.service.QualityQuestionInfoService;
import com.easylinkin.linkappapi.safe.dto.HiddenDangerPhotoAlbumDTO;
import com.easylinkin.linkappapi.safe.dto.HiddenDangerPhotoAlbumQueryDTO;
import com.easylinkin.linkappapi.safe.service.HiddenDangerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author xiaoyang
 * @version 1.0
 * @date 2022/08/18
 * @description 施工相册
 */
@RestController
@RequestMapping("photoAlbum")
@Api(tags = "施工相册")
public class PhotoAlbumController {

  @Autowired
  private HiddenDangerService hiddenDangerService;

  @Autowired
  private ElectricCheckService electricCheckService;

  @Autowired
  private QualityQuestionInfoService qualityQuestionInfoService;

  @Autowired
  private QualityAppraisingExcellentService qualityAppraisingExcellentService;

  @PostMapping("getHiddenDangerPage")
  @ApiOperation("查询隐患库相册分页")
  public RestMessage getHiddenDangerPage(@RequestBody RequestModel<HiddenDangerPhotoAlbumQueryDTO> requestModel) {
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");

    IPage<HiddenDangerPhotoAlbumDTO> record = hiddenDangerService.selectPhotoAlbumByPage(requestModel.getPage(),
        requestModel.getCustomQueryParams());

    return RestBuilders.successBuilder(record).build();
  }

  @PostMapping("countHiddenDanger")
  @ApiOperation("隐患库相册计数")
  public RestMessage countHiddenDanger(@RequestBody HiddenDangerPhotoAlbumQueryDTO dto){
    return RestBuilders.successBuilder(hiddenDangerService.photoAlbumCount(dto)).build();
  }

  @PostMapping("exportHiddenDanger")
  @ApiOperation("隐患库相册导出")
  public RestMessage exportHiddenDanger(@RequestBody HiddenDangerPhotoAlbumQueryDTO dto) {
    Assert.isTrue(CollectionUtil.isNotEmpty(dto.getIds()), "IDS不能为空");
    String fileName = hiddenDangerService.exportPhotoAlbum(dto);
    return RestBuilders.successBuilder().data(fileName).build();
  }

  @PostMapping("getElectricCheckPhotoPage")
  @ApiOperation("查询配电箱相册分页")
  public RestMessage getElectricCheckPhotoPage(@RequestBody RequestModel<ElectricCheckPhotoAlbumQueryDTO> requestModel) {
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");

    IPage<ElectricCheckPhotoAlbumDTO> record = electricCheckService.selectPhotoAlbumByPage(requestModel);

    return RestBuilders.successBuilder(record).build();
  }

  @PostMapping("countElectricCheckPhoto")
  @ApiOperation("配电箱相册计数")
  public RestMessage countElectricCheckPhoto(@RequestBody ElectricCheckPhotoAlbumQueryDTO dto){
    return RestBuilders.successBuilder(electricCheckService.photoAlbumCount(dto)).build();
  }

  @PostMapping("exportElectricCheck")
  @ApiOperation("配电箱相册导出")
  public RestMessage exportElectricCheck(@RequestBody ElectricCheckPhotoAlbumQueryDTO dto) {
    Assert.isTrue(CollectionUtil.isNotEmpty(dto.getIds()), "IDS不能为空");
    String fileName = electricCheckService.exportPhotoAlbum(dto);
    return RestBuilders.successBuilder().data(fileName).build();
  }

  @PostMapping("getQualityQuestionPhotoPage")
  @ApiOperation("查询质量问题相册分页")
  public RestMessage getQualityQuestionPhotoPage(@RequestBody RequestModel<QualityQuestionPhotoAlbumQueryDTO> requestModel) {
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");

    IPage<QualityQuestionPhotoAlbumDTO> record = qualityQuestionInfoService.selectPhotoAlbumByPage(requestModel.getPage(),
        requestModel.getCustomQueryParams());

    return RestBuilders.successBuilder(record).build();
  }

  @PostMapping("countQualityQuestionPhoto")
  @ApiOperation("质量问题相册计数")
  public RestMessage countQualityQuestionPhoto(@RequestBody QualityQuestionPhotoAlbumQueryDTO dto){
    return RestBuilders.successBuilder(qualityQuestionInfoService.photoAlbumCount(dto)).build();
  }

  @PostMapping("exportQualityQuestion")
  @ApiOperation("质量问题相册导出")
  public RestMessage exportQualityQuestion(@RequestBody QualityQuestionPhotoAlbumQueryDTO dto) {
    Assert.isTrue(CollectionUtil.isNotEmpty(dto.getIds()), "IDS不能为空");
    String fileName = qualityQuestionInfoService.exportPhotoAlbum(dto);
    return RestBuilders.successBuilder().data(fileName).build();
  }

  @PostMapping("getQualityAppraisingExcellentPhotoPage")
  @ApiOperation("查询质量评优相册分页")
  public RestMessage getQualityAppraisingExcellentPhotoPage(@RequestBody RequestModel<QualityAppraisingExcellentPhotoAlbumQueryDTO> requestModel) {
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");

    IPage<QualityAppraisingExcellentPhotoAlbumDTO> record = qualityAppraisingExcellentService.selectPhotoAlbumByPage(requestModel.getPage(),
        requestModel.getCustomQueryParams());

    return RestBuilders.successBuilder(record).build();
  }

  @PostMapping("countQualityAppraisingExcellentPhoto")
  @ApiOperation("质量评优相册计数")
  public RestMessage countQualityAppraisingExcellentPhoto(@RequestBody QualityAppraisingExcellentPhotoAlbumQueryDTO dto){
    return RestBuilders.successBuilder(qualityAppraisingExcellentService.photoAlbumCount(dto)).build();
  }

  @PostMapping("exportQualityAppraisingExcellent")
  @ApiOperation("质量评优相册导出")
  public RestMessage exportQualityAppraisingExcellent(@RequestBody QualityAppraisingExcellentPhotoAlbumQueryDTO dto) {
    Assert.isTrue(CollectionUtil.isNotEmpty(dto.getIds()), "IDS不能为空");
    String fileName = qualityAppraisingExcellentService.exportPhotoAlbum(dto);
    return RestBuilders.successBuilder().data(fileName).build();
  }
}
